package concurrent;

public class SynchronizedTest4 implements Runnable {
    static int i = 0;

    public static void main(String[] args) throws InterruptedException {
        for (int j = 0; j < 3; j++) {
            Thread t = new Thread(new SynchronizedTest4(), "Thread_" + j);
            t.start();
            Thread.sleep(1000L);
        }
    }


    @Override
    public void run() {
        synchronized (SynchronizedTest4.class) {
            System.out.println(i);
            if (i < 2) {
                i++;
                try {
                    SynchronizedTest4.class.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } else {
                System.out.println("notifyAll");
                SynchronizedTest4.class.notifyAll();
            }
            System.out.println(Thread.currentThread().getName());
        }
    }
}
